package cn.hairui.blog.mapper;

import cn.hairui.blog.model.Link;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import tk.mybatis.mapper.common.BaseMapper;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * <h2>请添加说明
 * </h2>
 * <ol>请添加详细说明
 * </ol>
 *
 * <h2>修改历史
 * </h2>
 * <ol>如有修改，请添加修改历史
 * </ol>
 *
 * </p>
 *
 * @author laoganbu
 * @version V1.0
 * @date 2019/7/29 19:14
 */
@Mapper
public interface LinkMapper extends BaseMapper<Link> {

    @Select("SELECT * FROM LINK WHERE STATUS=#{status} LIMIT 0,#{count}")
    List<Link> findLimited(String status, int count);

    @Select("SELECT id as id,webname as webname,motto as motto,url as url,webicon as webicon,webmaster as webmaster,phone as phone,email as email,case status when '0' then '待审核' when '1' then '审核通过' when '2' then '审核不通过' else '未知状态' end as status FROM LINK ORDER BY ID ASC")
    List<Map> list();

    @Delete("DELETE FROM LINK WHERE ID=#{id}")
    void deleteById(int id);

    @Select("SELECT * FROM LINK WHERE ID=#{id}")
    Link find(int id);

    @Update("UPDATE LINK SET STATUS=#{status} WHERE ID=#{id}")
    void updateSts(int id, int status);
}
